#include "KamaCoder.h"

const int MAX_INT = 23154;

// 存在一种情况：图中可能出现负权回路
int KamaCoder95::run() {
  int n, m, p1, p2, val;
  cin >> n >> m;

  vector<vector<int>> grid;

  for (int i = 0; i < m; i++) {
    cin >> p1 >> p2 >> val;
    // p1 -> p2, 权值为val
    grid.push_back({p1, p2, val});
  }

  int start = 1;  // 起点
  int end = n;    // 终点

  vector<int> minDist(n + 1, MAX_INT);
  minDist[start] = 0;

  bool flag = false;
  for (int i = 1; i <= n; i++) {  // 松弛n次,最后一次判断负权回路
    for (vector<int> &side : grid) {
      int from = side[0];
      int to = side[1];
      int price = side[2];
      if (i < n) {  // 前面的n-1次松弛
        if (minDist[from] != MAX_INT && minDist[to] > minDist[from] + price) {
          minDist[to] = minDist[from] + price;
        }
      } else {  // 如果形成负权回路的话，还能minDist[to]减少
        if (minDist[from] != MAX_INT && minDist[to] > minDist[from] + price) {
          flag = true;
        }
      }
    }
  }

  if (flag)
    cout << "circle" << endl;
  else if (minDist[end] == MAX_INT) {
    cout << "unconnected" << endl;
  } else {
    cout << minDist[end] << endl;
  }

  return 0;
}